package com.gitee.wsl.func.transform.sample

import com.gitee.wsl.func.transform.Transformer


/**
 * Transformer implementation that does nothing.
 *
 * @param <T> the type of the input and result to the function.
 * @since 3.0
</T> */
class NOPTransformer<T>
private constructor() : Transformer<T, T> {
    /**
     * Returns the singleton instance.
     *
     * @return the singleton instance.
     */
    private fun readResolve(): Any {
        return INSTANCE
    }

    /**
     * Transforms the input to result by doing nothing.
     *
     * @param input  the input object to transform
     * @return the transformed result which is the input
     */
    override fun transform(input: T): T {
        return input
    }

    companion object {

        /** Singleton predicate instance  */
        val INSTANCE = NOPTransformer<Any>()

        /**
         * Factory returning the singleton instance.
         *
         * @param <T>  the input/output type
         * @return the singleton instance
         * @since 3.1
        </T> */
        fun <T> nopTransformer(): Transformer<T, T> {
            return INSTANCE as Transformer<T, T>
        }
    }
}
